home *** CD-ROM | disk | FTP | other *** search
- /*
- This demo is written by Per Bratt.
-
- It can (should) be spread as long as it isn't changed and
- my name/address is in it.
- The sourche can NOT be separated from the program.
-
- The program is CARDWARE. If you like it (or if you don't)
- send a card to
-
- Per Bratt
- Döbelnsgatan 10 A
- 752 37 Uppsala
- Sweden
-
- or email me at
-
- perbratt@canit.se
-
- To the same addresses, you can send questions, suggestions,
- statemenst, money (Im pooooor) and bug-reports.
- If you'd like the source commented, I'll gladly do it.
- Everything will be answered
-
- The source is ( except for Commodores headerfiles )
- ready to be compiled. I used SAS C 5.10 and it's
- assembler, but the file could probably be compiled with other
- compilers too.
-
- Thanks to:
-
- Ander Bjerin ( the C-guru ), Per Helldahl ( suggestions, support )
- Henrik Anniko ( support ), Stig Bratt ( support, suggestions ).
-
- The program:
- This is just a demo of a snowfall. Tested on both A500 and A1200.
-
- Bugs:
- None yet, but the randomfunction could be better.
- Can YOU fix it?
-
- */
-
- #include <graphics/view.h>
- #include <graphics/gfxbase.h>
- #include <graphics/gfxmacros.h>
- #include <time.h>
-
- struct GfxBase *GfxBase;
-
- extern void __asm wp(register __a0 UBYTE *, register __d0 WORD, register __d1 WORD);
- extern BYTE __asm sno(register __a0 UBYTE *, register __d0 WORD, register __d1 WORD);
-
- struct View pview;
- struct View *oview;
- struct ViewPort pvport;
- struct RasInfo prasinfo;
- struct BitMap pbitmap[3];
- struct RastPort prp[3];
- struct cprlist *lofcprlist[2];
-
- char *LeftMouse = (char *) 0xbfe001;
- char *ClockLow = (char *) 0xbfe801;
-
- UBYTE *version = "$VER: Snowfall by Per Bratt. Version 1.12";
-
- WORD colour_table[] = {0x000B, 0x0FFF};
-
- void main();
-
- void main()
- {
- UWORD *pointer;
- SHORT x,y=0,points[50][4];
- UBYTE antal=0,number=0,hogst=255;
- BOOL klar=FALSE;
- BYTE ett=1,k;
- UWORD klocka,slump[10];
-
- for(y=0;y<50;y++)
- {
- for(x=0;x<4;x++) points[y][x]=0;
- }
-
- GfxBase=(struct GfxBase *) OpenLibrary("graphics.library",0);
- if(GfxBase==NULL) exit(0);
-
- oview=GfxBase->ActiView;
-
-
- InitView(&pview);
- pview.ViewPort = &pvport;
- InitVPort(&pvport);
- pvport.DWidth = 320;
- pvport.DHeight = 256;
- pvport.RasInfo = &prasinfo;
- pvport.Modes = NULL;
- pvport.SpritePriorities = NULL;
- pvport.DxOffset=0;
- pvport.DyOffset=0;
-
- pvport.ColorMap = (struct ColorMap *) GetColorMap( 2 );
-
- if(pvport.ColorMap==NULL) exit(0);
-
- pointer = (UWORD *) pvport.ColorMap->ColorTable;
-
- for(x=0;x<2;x++) *pointer++ = colour_table[x];
-
- for(y=0;y<3;y++)
- {
-
- InitBitMap(&pbitmap[y],1,320,256);
-
- for(x=0;x<1;x++)
- {
- pbitmap[y].Planes[x]=(PLANEPTR) AllocRaster(320,256);
- if(pbitmap[y].Planes[x]==NULL) exit(0);
- BltClear(pbitmap[y].Planes[x],RASSIZE(320,256),0);
- }
- }
- prasinfo.BitMap = &pbitmap[0];
- prasinfo.RxOffset=0;
- prasinfo.RyOffset=0;
- prasinfo.Next = NULL;
-
- MakeVPort(&pview, &pvport);
- MrgCop(&pview);
-
- lofcprlist[0] = pview.LOFCprList;
-
- pview.LOFCprList = NULL;
-
- prasinfo.BitMap = &pbitmap[1];
-
- MakeVPort(&pview, &pvport);
- MrgCop(&pview);
-
- lofcprlist[1] = pview.LOFCprList;
-
- for(x=0; x<3; x++)
- {
-
- InitRastPort(&prp[x]);
- prp[x].BitMap=&pbitmap[x];
-
-
- SetAPen(&prp[x],1);
- }
-
- ett=1;
-
- srand(time(NULL));
- for(x=0;x<10;x++)
- {
- slump[x]=rand()%11;
- }
-
-
- while((*LeftMouse & 0x40)==0x40)
- {
- BltClear(pbitmap[ett].Planes[0],RASSIZE(320,hogst),0);
- BltBitMap(&pbitmap[2],0,hogst,&pbitmap[ett],0,hogst,320,255+1-hogst,0xC0,0xFF,NULL);
- if(antal>0)
- {
-
- for(y=0;y<(antal+1);y++)
- {
-
- klar=FALSE;
- if(points[y][3]==0) goto nope;
- for(k=points[y][2];k>1;k--)
- {
- if(sno(pbitmap[2].Planes[0],points[y][0],points[y][1]+k)==0 && points[y][1]+k<256) break;
- }
- points[y][1]+=k;
- if(points[y][1]>254) klar=TRUE;
- else if(sno(pbitmap[2].Planes[0],points[y][0],points[y][1]+1)==1)
- {
- if(sno(pbitmap[2].Planes[0],points[y][0]-1,points[y][1]+1)==0 && points[y][0]>0) points[y][0]--;
- else if(sno(pbitmap[2].Planes[0],points[y][0]+1,points[y][1]+1)==0 && points[y][0]<319) points[y][0]++;
- else klar=TRUE;
- }
- nope:
- if(klar==TRUE)
- {
- if(points[y][1]<hogst) hogst=points[y][1];
- wp(pbitmap[2].Planes[0],points[y][0],points[y][1]);
- points[y][3]=0;
- }
-
- }
- WaitBlit();
- for(y=0;y<antal+1;y++) if(points[y][3]==1) wp(pbitmap[ett].Planes[0],points[y][0],points[y][1]);
- }
-
- klocka=*ClockLow;
- if(klocka%5==3)
- {
- for(number=0;number<50;number++) if(points[number][3]==0) break;
- if(number>antal) antal=number;
- points[number][0]=((slump[(number*9)%10]*klocka)%321);
- points[number][1]=0;
- points[number][2]=(klocka%3)+1;
- points[number][3]=1;
- }
-
-
- pview.LOFCprList = lofcprlist[ett];
- LoadView(&pview);
- ett=ett^1;
- WaitTOF();
- }
-
- LoadView(oview);
- for(y=0;y<2;y++)
- {
- FreeCprList(lofcprlist[y]);
- for(x=0;x<1;x++)
- FreeRaster(pbitmap[y].Planes[x],320,256);
- }
- FreeVPortCopLists(&pvport);
- FreeColorMap(pvport.ColorMap);
-
- CloseLibrary(GfxBase);
-
- }
-
-